package com.ruix.app.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;

import com.ruix.app.R;
import com.ruix.app.adapter.superadapter.SuperAdapter;
import com.ruix.app.adapter.superadapter.internal.SuperViewHolder;
import com.ruix.app.model.MessageModel;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by hadexs on 2017/5/7.
 */

public class MessageListAdapter extends SuperAdapter<MessageModel>{

    private  SimpleDateFormat format;
    private  int grennColor = 0xFFE4F8F3;
    private  int BGColor = 0xFFF9F9F9;

    public MessageListAdapter(Context context) {
        super(context, R.layout.item_message_list);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int position, MessageModel item) {
        holder.setText(R.id.tv_msg_title,item.getMessageTitle());
        holder.setText(R.id.tv_msg_content,item.getOriginContent());
        holder.setText(R.id.tv_msg_tag_from,String.format("来自：%s", item.getFromCname()));

        holder.setText(R.id.tv_msg_time,buildeDisplayTime(item.getCreatedTime()));
        holder.setSimpleDraweeURI(R.id.sdv_user_avatar,item.getFromAvatar());

        if (item.isRead()){
            holder.setBackgroundColor(R.id.rl_message_contain, BGColor);
        } else {
            holder.setBackgroundColor(R.id.rl_message_contain, grennColor);
        }
    }


    private String buildeDisplayTime(long ceratedTime) {
        if (ceratedTime > 0) {
            if (format == null) {
                format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
            }
            Date d1 = new Date(ceratedTime);
            return format.format(d1);
        }
        return "";
    }



}
